<template>
  <div class="app-container">

    <el-form ref="listQuery" :model="listQuery" :inline="true">

      <el-form-item label="标题" prop="title">
        <el-input
          v-model="listQuery.title"
          placeholder="请输入标题"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="getList"
        />
      </el-form-item>
      <el-form-item label="发布人" prop="creator">
        <el-input
          v-model="listQuery.creator"
          placeholder="请输入发布人姓名"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="getList"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="getList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" stripe :data="msgList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="#" type="index" width="80" align="center" />
      <el-table-column label="标题" prop="title" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="消息类型" prop="msgType" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>系统消息</span>
        </template>
      </el-table-column>
      <el-table-column label="发布人" prop="creator" align="center" :show-overflow-tooltip="true" />
      <el-table-column label="发布时间" align="center" prop="create_time" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.create_time) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="阅读状态" :show-overflow-tooltip="true" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.is_read === 0" type="danger">未读</el-tag>
          <el-tag v-if="scope.row.is_read === 1" type="success">已读</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="130" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleView(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageIndex"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <NoticeDetail ref="noticeDetail" @refreshList="getList" />
  </div>
</template>

<script>
import { noticeList } from '@/api/process/notice'
import NoticeDetail from '@/components/notice/detail'
// 搜索
export default {
  components: { NoticeDetail },
  data() {
    return {
      dialogVisible: false,
      queryParams: {},
      total: 0,
      loading: false,
      msgList: [],
      listQuery: {
        pageIndex: 1,
        pageSize: 10,
        title: '',
        creator: ''
      }
    }
  },
  created() {

  },
  mounted() {
    this.getList()
  },
  methods: {

    resetQuery() {
      this.timeValue = ''
      this.resetForm('listQuery')
      this.getList()
    },

    getList() {
      this.loading = true
      this.listQuery.pageIndex = this.queryParams.pageIndex
      this.listQuery.pageSize = this.queryParams.pageSize
      noticeList(this.listQuery).then(response => {
        this.msgList = response.data.list
        this.queryParams.pageIndex = response.data.pageIndex
        this.queryParams.pageSize = response.data.pageSize
        this.total = response.data.count
        this.loading = false
      })
    },

    handleView(row) {
      this.$refs.noticeDetail.open(row)
    },
    handleSelectionChange() { }

  }
}
</script>

<style scoped></style>
